class Storage {
  constructor() {
    // this.storage = {};
    this.data = {
      bookList: wx.getStorageSync("bookList") || [],
      history: wx.getStorageSync("history") || [],
      groups: wx.getStorageSync("groups") || [],
      currentGroup: wx.getStorageSync("currentGroup") || null,
    };
    this.initSorage();
  }

  /**
   * 增加代理
   */
  initSorage() {
    this.data = new Proxy(this.data, {
      get(target, key) {
        return target[key];
      },
      set(target, key, value) {
        wx.setStorage({
          key: key,
          data: value,
        });
        target[key] = value;
        return true;
      },
    });
  }
}
const storage = new Storage();
export default storage;
